// $URL: http://mingw-lib.googlecode.com/svn/trunk/working/nam/nbr.h $
// $Rev: 173 $
// $Author: akio.miyoshi $
// $Date:: 2010-07-02 02:51:50 +0000#$

#ifndef NETWORKBATCHREQUEST_H
#define NETWORKBATCHREQUEST_H

#include <QtCore>
#include <QtNetwork>

class NetworkBatchRequest : public QThread
{
    Q_OBJECT
public:
	enum WaitType {
		ReadyRead = 0,
		Finished = 1,
		ReadyReadOrFinished = (ReadyRead|Finished)
	};
	NetworkBatchRequest(QNetworkReply *a_reply, QByteArray *a_response = 0, bool a_headerOnly = false);
	void wait();
	bool waitWithType(WaitType a_wait_type);
	QByteArray read(qint64 maxSize);

public:
	QByteArray *m_response;

private:
	WaitType m_wait_type;
    QNetworkReply *m_reply;
	//QByteArray *m_response;
	bool m_headerOnly;
	bool m_finished;
	bool m_read_ready;
	QEventLoop m_eventLoop;

private slots:
	void metaDataChanged();
    void replyReadyRead();
    void replyFinished();
};

#endif // NETWORKBATCHREQUEST_H
